package View;

import Controller.UserController;
import pojo.AppData;
import pojo.Car;
import pojo.RentalRecord;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class RentalVehicleModelDB extends AbstractTableModel {
    //Controller
    private UserController userController;

    String[] columnNames = new String[]{"订单ID","车辆ID","订单状态","费用","天数"};
    public List<RentalRecord> orders;

    {
        try {
            userController = new UserController();
            System.out.println(AppData.getUserId());
            //根据用户id获得订单信息
            orders = userController.getRentalRecordsByCustomerId(AppData.getUserId());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    // 返回一共有多少行
    @Override
    public int getRowCount() {
        if (orders==null){
            return 0;
        }
        return orders.size();
    }

    // 返回一共有多少列
    @Override
    public int getColumnCount() {
        return columnNames.length;
    }
    // 获取每一列的名称
    @Override
    public String getColumnName(int columnIndex) {
        return columnNames[columnIndex];
    }
    // 单元格是否可以修改
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }
    // 每一个单元格里的值
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        RentalRecord order =  orders.get(rowIndex);
        if (0 == columnIndex) {
            return order.getRecord_id();
        }
        if (1 == columnIndex) {
            return order.getCar_id();
        }
        if (2 == columnIndex) {
            return order.getRental_status();
        }
        if (3 == columnIndex) {
            return order.getRental_fee();
        }
        if (4 == columnIndex) {
            return order.getRental_days();
        }
        return null;
    }
}
